﻿<%@ Page Language="C#" AutoEventWireup="true"  Inherits="GovernmentOfficeProject.common.view.ViewPageBase" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>我的日程</title>
    <link href="/css/dailog.css" rel="stylesheet" type="text/css" />
    <link href="/css/calendar.css" rel="stylesheet" type="text/css" /> 
    <link href="/css/dp.css" rel="stylesheet" type="text/css" />   
    <link href="/css/alert.css" rel="stylesheet" type="text/css" /> 
    <link href="/css/main.css" rel="stylesheet" type="text/css" /> 
    <link rel="stylesheet" type="text/css" href="/lib/easyui/themes/icon.css"/>  
    <link rel="stylesheet" type="text/css" href="/lib/easyui/themes/bootstrap/easyui.css"/>

    <script src="/lib/jquery.js" type="text/javascript"></script>  
    
    <script src="/lib/Plugins/Common.js" type="text/javascript"></script>    
    <script src="/lib/Plugins/datepicker_lang_CH.js" type="text/javascript"></script>     
    <script src="/lib/Plugins/jquery.datepicker.js" type="text/javascript"></script>
      

    <script src="/lib/Plugins/jquery.alert.js" type="text/javascript"></script>    
    <script src="/lib/Plugins/jquery.ifrmdailog.js" defer="defer" type="text/javascript"></script>
    <script src="/lib/Plugins/wdCalendar_lang_CH.js" type="text/javascript"></script>    
    <script src="/lib/Plugins/jquery.calendar.js" type="text/javascript"></script> 
    <script type="text/javascript" src="/lib/easyui/jquery.easyui.min.js"></script> 
    <script src="/lib/common.js" type="text/javascript" ></script> 
    <script type="text/javascript" src="/lib/easyui/locale/easyui-lang-zh_CN.js"></script> 
    <script type="text/javascript">
        var isLdClalendar = getQueryStringByName("ldCalendar");
       
        var currentUserId = '<%=Request.QueryString["userId"] == null ? GovernmentOfficeProject.SysTools.SystemContext.CurrentUserID : Convert.ToDecimal(Request.QueryString["userId"]) %>';
        var buttons = <%= GovernmentOfficeProject.LevelBusinessLogic.BLL_SYSTEM.GetMenuButtonByMneuNoAndUserIdToJsion(
            Request.QueryString["userId"] == null ? GovernmentOfficeProject.SysTools.SystemContext.CurrentUserID : Convert.ToDecimal(Request.QueryString["userId"]),Request.QueryString["menuNo"]) %>;
        $(document).ready(function () {
            var enableDragStr = getQueryStringByName("enableDrag")
            var currentView = "week";
            
            var view = "week";
            var readonly = true;
            var enableDrag = false;
            var deletable = false;
            var editable = false;
            
            //启用拖拽
            if(enableDragStr == "true"){
                enableDrag = true;
                $("#enableDragCheckbox").attr('checked','true');
            }
            
            
            if (buttons.indexOf('add') != -1) {
                $("#btn_add").css("display","");
                readonly = false;
            }
            if(buttons.indexOf('modify') != -1){
                $("#enableDragContainer").css("display","");
                editable = true;
                //enableDrag = true;
            }
            
            if(buttons.indexOf('delete') != -1){
                deletable = true;
                $("#btn_del").css("display","");    
            }
            
            var DATA_FEED_URL = "/handler/CalendarDatafeed.ashx?userId="+currentUserId;
            if(isLdClalendar == "true"){
                DATA_FEED_URL = DATA_FEED_URL +"&ldCalendar=true";
            }
             
            var op = {
                view: view,
                theme: 3,
                enableDrag: enableDrag,
                readonly: readonly,
                showday: new Date(),
                EditCmdhandler: Edit,
                DeleteCmdhandler: Delete,
                ViewCmdhandler: View,
                onWeekOrMonthToDay: wtd,
                onBeforeRequestData: cal_beforerequest,
                onAfterRequestData: cal_afterrequest,
                onRequestDataError: cal_onerror,
                autoload: true,
                url: DATA_FEED_URL + "&method=list",
                quickAddUrl: DATA_FEED_URL + "&method=add",
                quickUpdateUrl: DATA_FEED_URL + "&method=update",
                quickDeleteUrl: DATA_FEED_URL + "&method=remove",
                deletable:deletable,
                editable:editable
            };
            var $dv = $("#calhead");
            var _MH = document.documentElement.clientHeight;
            var dvH =  2;
            op.height = _MH - dvH - 20;
            op.eventItems = [];

            var p = $("#gridcontainer").bcalendar(op).BcalGetOp();
            if (p && p.datestrshow) {
                $("#txtdatetimeshow").text(p.datestrshow);
            }
            $("#caltoolbar").noSelect();

            $("#hdtxtshow").datepicker({ picker: "#txtdatetimeshow", showtarget: $("#txtdatetimeshow"),
                onReturn: function (r) {
                    var p = $("#gridcontainer").gotoDate(r).BcalGetOp();
                    if (p && p.datestrshow) {
                        $("#txtdatetimeshow").text(p.datestrshow);
                    }
                }
            });
            function cal_beforerequest(type) {
                var t = "加载数据...";
                switch (type) {
                    case 1:
                        t = "加载数据...";
                        break;
                    case 2:
                    case 3:
                    case 4:
                        t = "The request is being processed ...";
                        break;
                }
                $("#errorpannel").hide();
                $("#loadingpannel").html(t).show();
            }
            function cal_afterrequest(type) {
                switch (type) {
                    case 1:
                        $("#loadingpannel").hide();
                        break;
                    case 2: $("#gridcontainer").reload();
                    case 3:
                    case 4:
                        $("#loadingpannel").html("成功!");
                        window.setTimeout(function () { $("#loadingpannel").hide(); }, 2000);
                        break;
                }

            }
            function cal_onerror(type, data) {
                $("#errorpannel").show();
            }
            function Edit(data) {
                var eurl = "CalendarAddAndEdit.aspx?id={0}&start={2}&end={3}&isallday={4}&title={1}&userId="+currentUserId;
                if (data) {
                    var url = StrFormat(eurl, data)+"&buttons="+buttons;
                    if(isLdClalendar == "true"){
                       url = url+"&ldCalendar=true";
                    }
                    
                    OpenModelWindow(url, { width: 650, height: 450, caption: "修改日程详细信息", onclose: function () {
                        $("#gridcontainer").reload();
                    } 
                    });
                }
            }
            function View(data) {
                var str = "";
                $.each(data, function (i, item) {
                    str += "[" + i + "]: " + item + "\n";
                });
                alert(str);
            }
            function Delete(data, callback) {

                $.alerts.okButton = "确定";
                $.alerts.cancelButton = "取消";
                hiConfirm("您确定要删除当前日程吗？", '确认', function (r) { r && callback(0); });
            }
            function wtd(p) {
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
                $("#caltoolbar div.fcurrent").each(function () {
                    $(this).removeClass("fcurrent");
                })
                $("#showdaybtn").addClass("fcurrent");
            }
            //to show day view
            $("#showdaybtn").click(function (e) {
                //document.location.href="#day";
                currentView = "day";
                //显示选择时间及启动拖拽控件
                $("#dateBtnContainer").show();
                $("#dvCalMain").show();
                $("#dg").hide();
                
                $("#caltoolbar div.fcurrent").each(function () {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("day").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
                $("#gridcontainer").reload();
            });
            //to show week view
            $("#showweekbtn").click(function (e) {
                //document.location.href="#week";
                currentView = "week";
                //显示选择时间及启动拖拽控件
                $("#dateBtnContainer").show();
                $("#dvCalMain").show();
                $("#dg").hide();
                
                $("#caltoolbar div.fcurrent").each(function () {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("week").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }

                $("#gridcontainer").reload();
            });
            //to show month view
            $("#showmonthbtn").click(function (e) {
                //document.location.href="#month";
                currentView = "month";
                //显示选择时间及启动拖拽控件
                $("#dateBtnContainer").show();
                $("#dvCalMain").show();
                $("#dg").hide();
                
                $("#caltoolbar div.fcurrent").each(function () {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                var p = $("#gridcontainer").swtichView("month").BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
                
            });
            //to show list view
            $("#showlistbtn").click(function (e) {
                currentView = "list";
                //隐藏选择时间及启动拖拽控件
                $("#dateBtnContainer").hide();
                //设置按钮样式
                $("#caltoolbar div.fcurrent").each(function () {
                    $(this).removeClass("fcurrent");
                })
                $(this).addClass("fcurrent");
                $("#dvCalMain").hide();
                $("#dg").show();
            
                //初始化列表
                $("#dg").datagrid({  
                    url:DATA_FEED_URL+"&method=gridlist", 
                    height:document.body.clientHeight-35,
                    toolbar:'#toolbar',
                    pagination:true,
                    rownumbers:true,
                    fitColumns:true,
                    singleSelect:true,
                    columns:[[  
                        {field:'Title',title:'标题',width:100},  
                        {field:'StartTime',title:'开始时间',width:100},  
                        {field:'EndTime',title:'结束时间',width:100},
                        {field:'Location',title:'地点',width:100},  
                        {field:'Content',title:'日程描述',width:100}  
                    ]]  
                }); 
                
            });

            $("#showreflashbtn").click(function (e) {
                if(currentView == "list"){
                    $("#dg").datagrid('reload');
                }else{
                    $("#gridcontainer").reload();
                }
                
            });

            //Add a new event
            $("#faddbtn").click(function (e) {
                var url = "CalendarAddAndEdit.aspx?userId="+currentUserId;
                url = isLdClalendar == "true" ? url+"&ldCalendar=true" : url;
                OpenModelWindow(url, { width: 650, height: 400, caption: "创建新日程", onclose: function () {
                    if(currentView == "list"){
                        $("#dg").datagrid('reload');
                    }else{
                        $("#gridcontainer").reload();
                    }
                    
                }
                });
            });
            //go to today
            $("#showtodaybtn").click(function (e) {
                var p = $("#gridcontainer").gotoDate().BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }


            });
            //previous date range
            $("#sfprevbtn").click(function (e) {
                var p = $("#gridcontainer").previousRange().BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
                //取消了缓存机制 需每次刷新
                $("#gridcontainer").reload();
            });
            //next date range
            $("#sfnextbtn").click(function (e) {
                var p = $("#gridcontainer").nextRange().BcalGetOp();
                if (p && p.datestrshow) {
                    $("#txtdatetimeshow").text(p.datestrshow);
                }
                //取消了缓存机制 需每次刷新
                $("#gridcontainer").reload();
            });
            
            $("#enableDragCheckbox").change(function(){
                var currentUrl = document.URL;
                if(this.checked){
                    enableDrag = true;
                }else{
                    enableDrag = false;
                }
                if(currentUrl.indexOf("enableDrag") < 0){
                    currentUrl = currentUrl +"&enableDrag="+enableDrag.toString();
                }else{
                    if (enableDrag) {
                        currentUrl = currentUrl.replace('enableDrag=false','enableDrag=true');
                    }else{
                        currentUrl = currentUrl.replace('enableDrag=true','enableDrag=false');
                    }
                    
                }
                
                self.location=currentUrl;
                //alert(currentUrl);
            });
            
            //Search
            $("#btn_search").click(function () {
                $('#dg').datagrid('load', {  
                    Title: $("#txt_title").val(),  
                    StartTime: $("#txt_startTime").datetimebox('getValue'),
                    EndTime:$("#txt_endTime").datetimebox('getValue')
                });  
            });
            
            //Edit
            $("#btn_edit").click(function () {
                var row = $('#dg').datagrid('getSelected');
                if (row){  
                    var url = "CalendarAddAndEdit.aspx?id="+row.SceID+"&userId="+currentUserId+"&buttons="+buttons; 
                    if(isLdClalendar == "true"){
                       url = url+"&ldCalendar=true";
                    }
                    
                    OpenModelWindow(url, { width: 650, height: 450, caption: "修改日程详细信息", onclose: function () {
                        $("#dg").datagrid('reload');
                    } 
                    });
                } 
                
            });
            
            //Delete
             $("#btn_del").click(function () {
                var row = $('#dg').datagrid('getSelected');  
                if (row){  
                    $.messager.confirm('确认','您确定要删除当前日程吗?',function(r){  
                        if (r){
                            $.post('/handler/CalendarDatafeed.ashx?method=remove', { calendarId: row.SceID }, function(result) {
                                $("#loadingpannel").html(result.Msg).show();
                                window.setTimeout(function () { $("#loadingpannel").hide(); }, 2000);
                                if (result.IsSuccess) {
                                    $('#dg').datagrid('reload');    // reload the user data  
                                } 
                            },'json');  
                        }  
                    });  
                }  
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server" >
    <div>      
            <div id="caltoolbar" class="ctoolbar">
              <div id="faddbtn" class="fbutton">
                <div id="btn_add" style="display:none;"><span title='点击创建新日程' class="addcal">
                    新日程                
                </span></div>
            </div>
            <div class="btnseparator"></div>
             <div id="showtodaybtn" class="fbutton">
                <div><span title='点击返回到今天 ' class="showtoday">
                今天</span></div>
            </div>
              <div class="btnseparator"></div>

            <div id="showdaybtn" class="fbutton">
                <div><span title='日' class="showdayview">日</span></div>
            </div>
            <div  id="showweekbtn" class="fbutton fcurrent">
                <div><span title='周' class="showweekview">周</span></div>
            </div>
            
            <div  id="showmonthbtn" class="fbutton">
                <div><span title='月' class="showmonthview">月</span></div>
            </div>
            <div  id="showlistbtn" class="fbutton">
                <div><span title='日程列表' class="showmonthview">日程列表</span></div>
            </div>
            <div class="btnseparator"></div>
              <div  id="showreflashbtn" class="fbutton">
                <div><span title='刷新日程' class="showdayflash">刷新</span></div>
               </div>
            <div class="btnseparator"></div>
            
            <div id="dateBtnContainer">  
                <div id="sfprevbtn" title=""  class="fbutton">
                  <span class="fprev"></span>
                </div>
                <div id="sfnextbtn" title="" class="fbutton">
                    <span class="fnext"></span>
                </div>
                <div class="fshowdatep fbutton">
                    <div>
                        <input type="hidden" name="txtshow" id="hdtxtshow" />
                        <span id="txtdatetimeshow">选择日期</span>
                    </div>
                </div>
                
                <div  id="enableDragContainer" style="display:none;">
                    <div>
                        <span>　　　</span>
                        <input id="enableDragCheckbox" type="checkbox"  style="margin-top:5px;"/>
                        <span title='' >启用拖拽</span>
                    </div>
                </div>
            </div>
       
            <div id="loadingpannel" class="ptogtitle loadicon" style="display: none;">加载数据...</div>
            <div id="errorpannel" class="ptogtitle loaderror" style="display: none;">对不起, 不能加载您的数据，请稍后再试</div>
            <div class="clear"></div>
            </div>
      </div>
      <div style="padding:1px;">

        <div class="t1 chromeColor">
            &nbsp;</div>
        <div class="t2 chromeColor">
            &nbsp;</div>
        <div id="dvCalMain" class="calmain printborder">
            <div id="gridcontainer" style="overflow-y: visible;">
            </div>
        </div>
        <div id="listcontainer" style="overflow-y: visible;margin:0 -1px 0 -1px">
                <table id="dg" style="display:none; "></table>  
        </div>
        
        <div id="toolbar" style="display:none">
            <div>
                 标题 <input id="txt_title" type="text" style="border:solid 1px #ccc"/> 
                开始日期 <input id="txt_startTime" showSeconds="false" class="easyui-datebox" style="width:100px"/> 
                结束日期 <input id="txt_endTime"  showSeconds="false" class="easyui-datebox" style="width:100px"/> 
                <a href="javascript:void(0)" id="btn_search" class="easyui-linkbutton" iconCls="icon-search" >查询</a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="javascript:void(0)" id="btn_edit" class="easyui-linkbutton" iconCls="icon-edit" plain="true" >查看详细</a>  
                <a href="javascript:void(0)" id="btn_del" style="display:none;" class="easyui-linkbutton" iconCls="icon-remove" plain="true" >删除</a>  
            </div>
        </div>  
        <div class="t2 chromeColor">

            &nbsp;</div>
        <div class="t1 chromeColor">
            &nbsp;
        </div>   
        </div>
    </form>
</body>
</html>
